var _levelData;
var _settingData;
var _levelDone;
var _startData;
var _endData;

function initSaveData(){
	_levelData = sys.localStorage.getItem("_levelData");
	if(_levelData == ""){
		_levelData = "0";
	}
	_settingData = sys.localStorage.getItem("_settingData");
	if(_settingData == ""){
		_settingData = "true,false,false";
	}
	_levelDone = sys.localStorage.getItem("_levelDone");
	_startData = sys.localStorage.getItem("_startData");
	_endData = sys.localStorage.getItem("_endData");
}

function resetSaveData(){
	_levelData = sys.localStorage.setItem("_levelData","");
	_startData = sys.localStorage.setItem("_settingData","");
	_levelDone = sys.localStorage.setItem("_levelDone","");
	_startData = sys.localStorage.setItem("_startData","");
	_endData = sys.localStorage.setItem("_endData","");
	initSaveData();
}

function setLevelData(num){
	_levelData = num;
	sys.localStorage.setItem("_levelData",_levelData);
}

function getLevelData(){
	return _levelData;
}

function setSettingData(str,value){
	var strs = _settingData.split(",");
	switch(str){
		case "skipRead":{
			strs[0] = value;
			break;
		}
		case "skipAll":{
			strs[1] = value;
			break;
		}
		case "ignoreFail":{
			strs[2] = value;
			break;
		}
	}
	_settingData = "";
	for(var i = 0 ; i < strs.length ; i++){
		if(i != 0){
			_settingData += ",";
		}
		_settingData += strs[i];
	}
	sys.localStorage.setItem("_settingData",_settingData);
}

function getSettingData(str){
	var strs = _settingData.split(","); 
	switch(str){
	case "skipRead":{
		return strs[0];
	}
	case "skipAll":{
		return strs[1];
	}
	case "ignoreFail":{
		return strs[2];
	}
	}
	return "";
}

function setLevelDone(num){
	num = parseInt(num);
	var strs = _levelDone.split(","); 
	while(num >= strs.length){
		strs.push("");
	}
	strs[num] = "done";
	_levelDone = "";
	for(var i = 0 ; i < strs.length ; i++){
		if(i != 0){
			_levelDone += ",";
		}
		_levelDone += strs[i];
	}
	sys.localStorage.setItem("_levelDone",_levelDone);
}

function getLevelDone(num){
	num = parseInt(num);
	var strs = _levelDone.split(","); 
	if(num >= strs.length){
		return "";
	}
	return strs[num];
}

function setStartData(num){
	num = parseInt(num);
	var strs = _startData.split(","); 
	while(num >= strs.length){
		strs.push("");
	}
	strs[num] = "done";
	_startData = "";
	for(var i = 0 ; i < strs.length ; i++){
		if(i != 0){
			_startData += ",";
		}
		_startData += strs[i];
	}
	sys.localStorage.setItem("_startData",_startData);
}

function getStartData(num){
	num = parseInt(num);
	var strs = _startData.split(","); 
	if(num >= strs.length){
		return "";
	}
	return strs[num];
}

function setEndData(num){
	num = parseInt(num);
	var strs = _endData.split(","); 
	while(num >= strs.length){
		strs.push("");
	}
	strs[num] = "done";
	_endData = "";
	for(var i = 0 ; i < strs.length ; i++){
		if(i != 0){
			_endData += ",";
		}
		_endData += strs[i];
	}
	sys.localStorage.setItem("_endData",_endData);
}

function getEndData(num){
	num = parseInt(num);
	var strs = _endData.split(","); 
	if(num > strs.length){
		return "";
	}
	return strs[num];
}